from haystack import indexes
from post.models import *


#注意格式(模型类名+Index)
class PostIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)

    #给ptitle,pcontent设置索引
    ptitle = indexes.NgramField(model_attr='ptitle')
    pcontent = indexes.NgramField(model_attr='pcontent')

    def get_model(self):
        return Post

    def index_queryset(self, using=None):
        return self.get_model().objects.order_by('-create')
